package com.beiding.controller;

import com.beiding.dao.impl.SettingsHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/manager")
public class ManagerController {


    private SettingsHelper helper;

    @Autowired
    public void setHelper(SettingsHelper helper) {
        this.helper = helper;
    }

    //获取平台费率
    @Secured("ROLE_MANAGER_ORDER")
    @PostMapping("/platformCostRate-get")
    Double getPlatformCostRate(){
        return helper.getPlatformCostRate();
    }


    //设置平台费率
    @Secured("ROLE_MANAGER_ORDER")
    @PostMapping("/platformCostRate-set")
    Double setPlatformCostRate(@RequestParam(required = true) Double platformCostRate) {

        helper.setPlatformCostRate(platformCostRate);

        //返回修改后的平台费率
        return platformCostRate;
    }

    @Secured("ROLE_MANAGER_ORDER")
    @PostMapping("/timeout-set")
    Long setTimeout(@RequestParam(required = true) String item, @RequestParam(required = true) Long time) {
        helper.setTimeout(item,time);
        return time;
    }

    @Secured("ROLE_MANAGER_ORDER")
    @PostMapping("/timeout-get")
    List<SettingsHelper.TimeoutItem> setTimeout() {

        List<SettingsHelper.TimeoutItem> timeoutItems = helper.getTimeoutItems();

        return helper.getTimeoutItems();
    }




}
